{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "## Super Agent: Integrating Autogen Technologies and Vector Databases"
      ],
      "metadata": {
        "id": "WhLTlkxi1-ej"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "The Super Agent project showcases the integration of cutting-edge technologies including Ollama, LiteLLM, Autogen, LanceDB, and LangChain to create a powerful AI agent. This agent leverages the strengths of vector databases and conversational AI to provide sophisticated data management and context-aware interactions. The goal is to harness the capabilities of LanceDB's vector database and Autogen's conversational AI framework to build a Super Agent that excels in understanding and processing complex queries.\n",
        "\n",
        "![image.png]()"
      ],
      "metadata": {
        "id": "hRV9fV5f2ITG"
      }
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lHFbPb4JU9xF"
      },
      "source": [
        "This notebook  illustrates how you can use the Langchain with custom PDF data & chat it using an Autogen Agent."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "3poVgyh-bZJ-",
        "outputId": "3926d8ef-7528-47bd-d1f3-5b8ca479fe59"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\u001b[?25l   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/88.8 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m88.8/88.8 kB\u001b[0m \u001b[31m3.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h\u001b[?25l   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/1.0 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K   \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m58.3 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m20.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h\u001b[?25l   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/2.4 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K   \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m56.9 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m28.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.0/77.0 kB\u001b[0m \u001b[31m3.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m13.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m27.4/27.4 MB\u001b[0m \u001b[31m9.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m30.5/30.5 MB\u001b[0m \u001b[31m28.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m298.0/298.0 kB\u001b[0m \u001b[31m16.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m409.5/409.5 kB\u001b[0m \u001b[31m22.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m45.5/45.5 kB\u001b[0m \u001b[31m2.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m313.9/313.9 kB\u001b[0m \u001b[31m16.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.5/49.5 kB\u001b[0m \u001b[31m2.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h"
          ]
        }
      ],
      "source": [
        "%pip install pyautogen~=0.1.0  langchain langchain_community openai tiktoken lancedb pypdf -q -U"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {
        "id": "0tLTTT9ucFEb"
      },
      "outputs": [],
      "source": [
        "from langchain_community.embeddings import OpenAIEmbeddings\n",
        "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
        "from langchain.document_loaders import PyPDFLoader\n",
        "from langchain.memory import ConversationBufferMemory\n",
        "from langchain_community.llms import OpenAI\n",
        "from langchain.chains import ConversationalRetrievalChain\n",
        "from langchain_community.vectorstores import LanceDB"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ObNypsHRV3mz"
      },
      "source": [
        "Requirements\n",
        "AutoGen requires Python>=3.8.\n",
        "\n",
        "To run this notebook example, please install `pyautogen`:\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "6RuVu12whCG0",
        "outputId": "1b9b7d4c-000c-4ee8-afda-a7a9ae275cf4"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Requirement already satisfied: pyautogen in /usr/local/lib/python3.10/dist-packages (0.1.14)\n",
            "Requirement already satisfied: diskcache in /usr/local/lib/python3.10/dist-packages (from pyautogen) (5.6.3)\n",
            "Requirement already satisfied: flaml in /usr/local/lib/python3.10/dist-packages (from pyautogen) (2.3.2)\n",
            "Requirement already satisfied: openai<1 in /usr/local/lib/python3.10/dist-packages (from pyautogen) (0.28.1)\n",
            "Requirement already satisfied: python-dotenv in /usr/local/lib/python3.10/dist-packages (from pyautogen) (1.0.1)\n",
            "Requirement already satisfied: termcolor in /usr/local/lib/python3.10/dist-packages (from pyautogen) (2.5.0)\n",
            "Requirement already satisfied: requests>=2.20 in /usr/local/lib/python3.10/dist-packages (from openai<1->pyautogen) (2.32.3)\n",
            "Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from openai<1->pyautogen) (4.66.6)\n",
            "Requirement already satisfied: aiohttp in /usr/local/lib/python3.10/dist-packages (from openai<1->pyautogen) (3.11.2)\n",
            "Requirement already satisfied: NumPy>=1.17 in /usr/local/lib/python3.10/dist-packages (from flaml->pyautogen) (1.26.4)\n",
            "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai<1->pyautogen) (3.4.0)\n",
            "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai<1->pyautogen) (3.10)\n",
            "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai<1->pyautogen) (2.2.3)\n",
            "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai<1->pyautogen) (2024.8.30)\n",
            "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai<1->pyautogen) (2.4.3)\n",
            "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai<1->pyautogen) (1.3.1)\n",
            "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai<1->pyautogen) (24.2.0)\n",
            "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai<1->pyautogen) (1.5.0)\n",
            "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai<1->pyautogen) (6.1.0)\n",
            "Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai<1->pyautogen) (0.2.0)\n",
            "Requirement already satisfied: yarl<2.0,>=1.17.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai<1->pyautogen) (1.17.2)\n",
            "Requirement already satisfied: async-timeout<6.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai<1->pyautogen) (4.0.3)\n",
            "Requirement already satisfied: typing-extensions>=4.1.0 in /usr/local/lib/python3.10/dist-packages (from multidict<7.0,>=4.5->aiohttp->openai<1->pyautogen) (4.12.2)\n"
          ]
        }
      ],
      "source": [
        "!pip install pyautogen"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Add OpenAI API key as env variable"
      ],
      "metadata": {
        "id": "QR8SzHaH2f9L"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {
        "id": "sUFdvTyVh8xF"
      },
      "outputs": [],
      "source": [
        "import lancedb\n",
        "import os\n",
        "\n",
        "# setup OPENAI API KEY\n",
        "os.environ[\"OPENAI_API_KEY\"] = \"sk-proj-.....\"\n",
        "\n",
        "# initiate OPENAI Embedding function\n",
        "embeddings = OpenAIEmbeddings()"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Import data\n",
        "\n",
        "This example utilizes \"Food and Nutrition handbook by MINISTRY OF AGRICULTURE, ANIMAL INDUSTRY AND FISHERIES\" PDF which is imported from following code."
      ],
      "metadata": {
        "id": "QOi6vySd24k4"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ODKg12trdhX-",
        "outputId": "e1388dc8-83da-49ed-f7bc-999edf10cf21"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "--2024-12-04 18:08:56--  https://pdf.usaid.gov/pdf_docs/PA00TBCT.pdf\n",
            "Resolving pdf.usaid.gov (pdf.usaid.gov)... 23.54.221.184, 2600:1408:c400:1687::1923, 2600:1408:c400:1697::1923\n",
            "Connecting to pdf.usaid.gov (pdf.usaid.gov)|23.54.221.184|:443... connected.\n",
            "HTTP request sent, awaiting response... 200 OK\n",
            "Length: 6419525 (6.1M) [application/pdf]\n",
            "Saving to: ‘food.pdf’\n",
            "\n",
            "food.pdf            100%[===================>]   6.12M  --.-KB/s    in 0.08s   \n",
            "\n",
            "2024-12-04 18:08:56 (74.1 MB/s) - ‘food.pdf’ saved [6419525/6419525]\n",
            "\n"
          ]
        }
      ],
      "source": [
        "# !wget -O uniswap_v3.pdf https://uniswap.org/whitepaper-v3.pdf\n",
        "!wget -O food.pdf https://pdf.usaid.gov/pdf_docs/PA00TBCT.pdf"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "yV0pNPiRPy8h"
      },
      "source": [
        "# create file name with OAI_CONFIG_LIT.json"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "id": "yWDhjTDMcFBi"
      },
      "outputs": [],
      "source": [
        "# create file name with OAI_CONFIG_LIT.\n",
        "import json\n",
        "\n",
        "config = [{\"model\": \"gpt-4\", \"api_key\": os.environ[\"OPENAI_API_KEY\"]}]\n",
        "\n",
        "with open(\"OAI_CONFIG_LIST.json\", \"w\") as fp:\n",
        "    json.dump(config, fp)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1oC3NAFyd4Kb"
      },
      "source": [
        "**create OAI_CONFIG_LIST.json file in pwd & upload\n",
        "in it**\n",
        "\n",
        "\n",
        "[\n",
        "   {\n",
        "     \"model\": \"gpt-4\",\n",
        "     \"api_key\": \"sk-yourapikey\"\n",
        "   }\n",
        "]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {
        "id": "H1bRXWu-cE_C"
      },
      "outputs": [],
      "source": [
        "import autogen\n",
        "\n",
        "config_list = autogen.config_list_from_json(\n",
        "    \"OAI_CONFIG_LIST.json\",\n",
        "    filter_dict={\n",
        "        \"model\": [\"gpt-4\"],\n",
        "    },\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {
        "id": "5gapqmsscFG-"
      },
      "outputs": [],
      "source": [
        "# load imported dataset in PDF loader and split them in chunks\n",
        "loaders = [PyPDFLoader(\"./food.pdf\")]\n",
        "docs = []\n",
        "for l in loaders:\n",
        "    docs.extend(l.load())\n",
        "text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000)\n",
        "docs = text_splitter.split_documents(docs)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {
        "id": "5dLkCqa0dLXV"
      },
      "outputs": [],
      "source": [
        "import lancedb\n",
        "\n",
        "embeddings = OpenAIEmbeddings()\n",
        "# initiate LanceDB and ingest the splited chunks into it\n",
        "vectorstore = LanceDB.from_documents(documents=docs, embedding=embeddings)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {
        "id": "YMBoF5kucFMJ",
        "outputId": "97a0399e-0207-4867-f81a-cf3a168a981e",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "<ipython-input-16-70ff1d5b784c>:3: LangChainDeprecationWarning: The class `OpenAI` was deprecated in LangChain 0.0.10 and will be removed in 1.0. An updated version of the class exists in the :class:`~langchain-openai package and should be used instead. To use it run `pip install -U :class:`~langchain-openai` and import as `from :class:`~langchain_openai import OpenAI``.\n",
            "  OpenAI(\n",
            "<ipython-input-16-70ff1d5b784c>:7: LangChainDeprecationWarning: Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/\n",
            "  memory=ConversationBufferMemory(memory_key=\"chat_history\", return_messages=True),\n"
          ]
        }
      ],
      "source": [
        "# define a retrieval chain to start chatting with ingested data\n",
        "qa = ConversationalRetrievalChain.from_llm(\n",
        "    OpenAI(\n",
        "        temperature=0,\n",
        "    ),\n",
        "    vectorstore.as_retriever(),\n",
        "    memory=ConversationBufferMemory(memory_key=\"chat_history\", return_messages=True),\n",
        ")"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Start Querying\n",
        "\n",
        "Now we are ready to start query and get answers"
      ],
      "metadata": {
        "id": "I1WX_rCL4LHF"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {
        "id": "HjSVygLIcSEX"
      },
      "outputs": [],
      "source": [
        "# helper function to return responses in the form of answer of queries\n",
        "def answer_food_question(question):\n",
        "    response = qa({\"question\": question})\n",
        "    return response[\"answer\"]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 18,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 129
        },
        "id": "XCqxSaQSepsW",
        "outputId": "7a1a4813-b5d6-4f2d-d7be-9db09d82f6da"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "<ipython-input-17-e9499bd82ace>:3: LangChainDeprecationWarning: The method `Chain.__call__` was deprecated in langchain 0.1.0 and will be removed in 1.0. Use :meth:`~invoke` instead.\n",
            "  response = qa({\"question\": question})\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "' Good food is food that provides the recommended amounts of nutrients for the body to perform all its physiological activities. It is important to eat the right types of food, in the right amounts, at the right time, and prepared in the correct way and place. Good food is essential for physical and cognitive development, and it can improve overall health and quality of life.'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 18
        }
      ],
      "source": [
        "# query\n",
        "question = \"what is good food\"\n",
        "answer_food_question(question)"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Autogen\n",
        "\n",
        "Now lets try to go same using Autogen"
      ],
      "metadata": {
        "id": "Q-nTrPEf4gQG"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {
        "id": "BY4Fz-l7cUCA"
      },
      "outputs": [],
      "source": [
        "# install autogen\n",
        "!pip install pyautogen -q"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "anvuLAIycaqb"
      },
      "source": [
        "#### Set up AutoGen user agent and assistant agent with function calling enabled."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 20,
      "metadata": {
        "id": "Vca8Y_khcUID"
      },
      "outputs": [],
      "source": [
        "llm_config = {\n",
        "    \"request_timeout\": 600,\n",
        "    \"seed\": 42,\n",
        "    \"config_list\": config_list,\n",
        "    \"temperature\": 0,\n",
        "    \"functions\": [\n",
        "        {\n",
        "            \"name\": \"answer_food_question\",\n",
        "            \"description\": \"Answer to any quetion related to food & provided answer_food_question \",\n",
        "            \"parameters\": {\n",
        "                \"type\": \"object\",\n",
        "                \"properties\": {\n",
        "                    \"question\": {\n",
        "                        \"type\": \"string\",\n",
        "                        \"description\": \"The question to ask in relation to food\",\n",
        "                    }\n",
        "                },\n",
        "                \"required\": [\"question\"],\n",
        "            },\n",
        "        }\n",
        "    ],\n",
        "}"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 22,
      "metadata": {
        "id": "1XHjzIYAcfE7"
      },
      "outputs": [],
      "source": [
        "# create an AssistantAgent instance named \"assistant\"\n",
        "assistant = autogen.AssistantAgent(\n",
        "    name=\"assistant\",\n",
        "    llm_config=llm_config,\n",
        ")\n",
        "# create a UserProxyAgent instance named \"user_proxy\"\n",
        "user_proxy = autogen.UserProxyAgent(\n",
        "    name=\"user_proxy\",\n",
        "    human_input_mode=\"NEVER\",\n",
        "    max_consecutive_auto_reply=10,\n",
        "    code_execution_config={\"work_dir\": \".\"},\n",
        "    llm_config=llm_config,\n",
        "    system_message=\"\"\"Reply TERMINATE if the task has been solved at full satisfaction.\n",
        "Otherwise, reply CONTINUE, or the reason why the task is not solved yet.\"\"\",\n",
        "    function_map={\"answer_food_question\": answer_food_question},\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 23,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "hOZKxakHchZ4",
        "outputId": "f94afd08-4ca2-4a9b-939f-c3c8e1adf5bd"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "user_proxy (to assistant):\n",
            "\n",
            "\n",
            "what is good food?\n",
            "\n",
            "\n",
            "--------------------------------------------------------------------------------\n",
            "assistant (to user_proxy):\n",
            "\n",
            "***** Suggested function Call: answer_food_question *****\n",
            "Arguments: \n",
            "{\n",
            "  \"question\": \"what is good food?\"\n",
            "}\n",
            "*********************************************************\n",
            "\n",
            "--------------------------------------------------------------------------------\n",
            "\n",
            ">>>>>>>> EXECUTING FUNCTION answer_food_question...\n",
            "user_proxy (to assistant):\n",
            "\n",
            "***** Response from calling function \"answer_food_question\" *****\n",
            " Good food is any type of liquid, semi-solid, or solid substance that contains nutrients and nourishes the body when consumed. It is important because it provides the body with essential nutrients, promotes good health, and helps prevent illnesses and health problems. Good food should be eaten in appropriate amounts, at the right time, and prepared correctly to ensure a balanced diet. It should also include a variety of foods from each food group to meet the body's different needs.\n",
            "*****************************************************************\n",
            "\n",
            "--------------------------------------------------------------------------------\n",
            "assistant (to user_proxy):\n",
            "\n",
            "Good food is any type of liquid, semi-solid, or solid substance that contains nutrients and nourishes the body when consumed. It is important because it provides the body with essential nutrients, promotes good health, and helps prevent illnesses and health problems. Good food should be eaten in appropriate amounts, at the right time, and prepared correctly to ensure a balanced diet. It should also include a variety of foods from each food group to meet the body's different needs.\n",
            "\n",
            "TERMINATE\n",
            "\n",
            "--------------------------------------------------------------------------------\n",
            "user_proxy (to assistant):\n",
            "\n",
            "TERMINATE\n",
            "\n",
            "--------------------------------------------------------------------------------\n"
          ]
        }
      ],
      "source": [
        "# the assistant receives a message from the user, which contains the task description\n",
        "user_proxy.initiate_chat(\n",
        "    assistant,\n",
        "    message=\"\"\"\n",
        "what is good food?\n",
        "\"\"\",\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 24,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "UDXo2V06fNjz",
        "outputId": "17d8f392-fc9d-427e-b07e-57a045effaf0"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "user_proxy (to assistant):\n",
            "\n",
            "\n",
            "please explain me essential minerals, sources, functions and symptoms of\n",
            "deficiency?\n",
            "\n",
            "\n",
            "--------------------------------------------------------------------------------\n",
            "assistant (to user_proxy):\n",
            "\n",
            "Sure, here are some essential minerals, their sources, functions, and symptoms of deficiency:\n",
            "\n",
            "1. Calcium:\n",
            "   - Sources: Dairy products, leafy green vegetables, fish with edible bones (like sardines and salmon), fortified foods.\n",
            "   - Functions: Necessary for bone health, muscle function, nerve transmission, blood clotting.\n",
            "   - Deficiency Symptoms: Osteoporosis, muscle cramps, dental problems, brittle nails.\n",
            "\n",
            "2. Iron:\n",
            "   - Sources: Red meat, poultry, eggs, fruits, green vegetables, fortified bread.\n",
            "   - Functions: Essential for the production of red blood cells, carries oxygen in the blood.\n",
            "   - Deficiency Symptoms: Anemia, fatigue, weakness, pale skin, shortness of breath.\n",
            "\n",
            "3. Potassium:\n",
            "   - Sources: Bananas, oranges, cantaloupes, raisins, nuts, fish, and whole grains.\n",
            "   - Functions: Helps maintain fluid balance, helps control the electrical activity of the heart, helps with muscle contractions.\n",
            "   - Deficiency Symptoms: Weakness, fatigue, muscle cramps, constipation.\n",
            "\n",
            "4. Magnesium:\n",
            "   - Sources: Green leafy vegetables, nuts, seeds, dry beans, whole grains, and low-fat dairy products.\n",
            "   - Functions: Involved in over 300 biochemical reactions in the body, including nerve and muscle function, bone health, and regulating blood sugar levels.\n",
            "   - Deficiency Symptoms: Loss of appetite, nausea, fatigue, and weakness. In severe cases, numbness, muscle cramps, seizures, personality changes, abnormal heart rhythms.\n",
            "\n",
            "5. Zinc:\n",
            "   - Sources: Meat, shellfish, legumes, seeds, nuts, dairy, eggs, whole grains.\n",
            "   - Functions: Supports the immune system, necessary for the sense of taste and smell, needed for wound healing.\n",
            "   - Deficiency Symptoms: Loss of appetite, impaired immune function, hair loss, diarrhea, delayed sexual maturation, impotence.\n",
            "\n",
            "Remember, it's always best to get your minerals from a balanced diet rather than supplements unless advised by a healthcare provider. Overdosing on minerals can be harmful. Always consult with a healthcare provider for personalized advice.\n",
            "\n",
            "--------------------------------------------------------------------------------\n",
            "user_proxy (to assistant):\n",
            "\n",
            "TERMINATE\n",
            "\n",
            "--------------------------------------------------------------------------------\n"
          ]
        }
      ],
      "source": [
        "# the assistant receives a message from the user, which contains the task description\n",
        "user_proxy.initiate_chat(\n",
        "    assistant,\n",
        "    message=\"\"\"\n",
        "please explain me essential minerals, sources, functions and symptoms of\n",
        "deficiency?\n",
        "\"\"\",\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 25,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "UrlFGYW0g0sJ",
        "outputId": "b4233ec2-680b-44d7-a491-91888c3bad10"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "user_proxy (to assistant):\n",
            "\n",
            "\n",
            "which food Keeps eyes healthy ?\n",
            "\n",
            "\n",
            "--------------------------------------------------------------------------------\n",
            "assistant (to user_proxy):\n",
            "\n",
            "***** Suggested function Call: answer_food_question *****\n",
            "Arguments: \n",
            "\n",
            "{\n",
            "  \"question\": \"which food Keeps eyes healthy ?\"\n",
            "}\n",
            "*********************************************************\n",
            "\n",
            "--------------------------------------------------------------------------------\n",
            "\n",
            ">>>>>>>> EXECUTING FUNCTION answer_food_question...\n",
            "user_proxy (to assistant):\n",
            "\n",
            "***** Response from calling function \"answer_food_question\" *****\n",
            " Foods rich in Vitamin A, such as liver, egg yolk, dairy products, and dark green and deep yellow fruits and vegetables, can help maintain healthy eyes.\n",
            "*****************************************************************\n",
            "\n",
            "--------------------------------------------------------------------------------\n",
            "assistant (to user_proxy):\n",
            "\n",
            "Foods that are rich in Vitamin A can help maintain healthy eyes. These include:\n",
            "\n",
            "1. Liver\n",
            "2. Egg yolk\n",
            "3. Dairy products\n",
            "4. Dark green fruits and vegetables\n",
            "5. Deep yellow fruits and vegetables\n",
            "\n",
            "These foods are beneficial for eye health because Vitamin A plays a crucial role in vision by maintaining a clear cornea, which is the outside covering of your eye. \n",
            "\n",
            "TERMINATE\n",
            "\n",
            "--------------------------------------------------------------------------------\n",
            "user_proxy (to assistant):\n",
            "\n",
            "TERMINATE\n",
            "\n",
            "--------------------------------------------------------------------------------\n"
          ]
        }
      ],
      "source": [
        "# the assistant receives a message from the user, which contains the task description\n",
        "user_proxy.initiate_chat(\n",
        "    assistant,\n",
        "    message=\"\"\"\n",
        "which food Keeps eyes healthy ?\n",
        "\"\"\",\n",
        ")"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}